public with sharing class InstallationReportController {

	public WorkOrder__c workOrder{get;set;}

	public Id id{get;set;}

	public String instruction {get;set;}
	public String installationDebugging{get;set;}

	public Attachment useSign {get;set;}
	public Attachment manageSign {get;set;}
	public String useSignDate{get;set;}
	public String manageSignDate{get;set;}

	public Attachment engineerSign{get;set;}
	public String engineerSignDate{get;set;}
	public String engineerName {get;set;}//工程师 经销商工单取 服务工程师名字 否则 技术人员
	public String serEndTime {get;set;}
	public String serStartTime {get;set;}
	public String deviceName {get; private set;}
	public String installDate {get; private set;}

    public InstallationReportController(ApexPages.StandardController con) {
        id=con.getId();
        workOrder = [	SELECT 
        					//使用科室
        					w.UserDepartmen__c,w.UserDepartmentContact__r.Name,w.UseDeptTeleNo__c,
        					//管理科室
        					w.ManagementDep__c,w.ManagementDepContact__r.Name,w.ManageDeptTeleNo__c,
        					w.Name,w.IMEINumber__c,w.IMEINumber_F__c,
        					w.ActuallyWorkTime__c,w.DealerNameTxt__c,w.SN__c,InstallData__c,
        					w.Install_Start_Datetime__c,w.Install_End_Datetime__c,w.InstallRequestDate__c,
        					w.TransportTime__c,w.Maintenance_Info__c,w.Reason_Desc__c,w.Fault_Freq__c,
        					w.ProblemType__c,w.Software_Name__c,w.Ship_No__c,
        					w.Reporter_Version__c,InstallationDebugging__c,Instruction__c,
        					w.Software_Version__c,w.WarrantyStatus__c,w.QCI_A__c,w.Software__c,
        					//客户
        					w.Account__r.Name,w.Account__r.Address__c,w.Account__r.Postcode__c,w.Account__r.Province__c,w.Account__r.City__c,
        					//产品
        					w.ManufactureInfo__r.Name,w.ManufactureInfo__r.Model__c,w.ManufactureInfo__r.SoftwareVersion__c,w.ManufactureInfo__r.ProductName__c, 
        					//安装情况
        					w.Technician__r.Name,w.Case__r.ServiceEngineerName__c,w.Case__r.RecordType.DeveloperName,
                     
        				    NormalRequirement1__c,ActualSituation1__c,IsMeetRequirement1__c,
							NormalRequirement2__c,ActualSituation2__c,IsMeetRequirement2__c,
							NormalRequirement3__c,ActualSituation3__c,IsMeetRequirement3__c,
							NormalRequirement4__c,ActualSituation4__c,IsMeetRequirement4__c,
							NormalRequirement5__c,ActualSituation5__c,IsMeetRequirement5__c,
							NormalRequirement6__c,ActualSituation6__c,IsMeetRequirement6__c,
							NormalRequirement7__c,ActualSituation7__c,IsMeetRequirement7__c,
							NormalRequirement8__c,ActualSituation8__c,IsMeetRequirement8__c,
							NormalRequirement9__c,ActualSituation9__c,IsMeetRequirement9__c,
							NormalRequirement11__c,ActualSituation11__c,IsMeetRequirement11__c,
							NormalRequirement10__c,ActualSituation10__c,IsMeetRequirement10__c
        				FROM WorkOrder__c w 
						WHERE w.Id = :id ];
		if(null!=workOrder){
			List<Attachment> attachment= [	SELECT Body,Name,CreatedDate,Id 
											FROM Attachment 
											WHERE ParentId = :id order by CreatedDate];
			for(Attachment att : attachment){
				if (att.Name=='使用科室负责人_Sign.jpg'){
					useSign=att;
				}else if( att.Name=='管理科室负责人_Sign.jpg'){
					manageSign=att;
				}else if( att.Name == '工程师_Sign.jpg'){
					engineerSign = att;
				}
			}

			installDate =  workOrder.InstallData__c != null ? Datetime.newInstance(workOrder.InstallData__c.Year(),workOrder.InstallData__c.Month(),workOrder.InstallData__c.day()).format('yyyy年MM月dd日'):'';
			
            //deviceName = Utils.wrapWordInPdf('全自动化学发光测定仪IS1200全自动化学发光测定仪IS1200','\n' ,21);
           deviceName = Utils.wrapWordInPdf(workOrder.ManufactureInfo__r.ProductName__c  ,'\n',21);
			
			serStartTime = workOrder.Install_Start_Datetime__c != null ? workOrder.Install_Start_Datetime__c.format('yyyy年MM月dd日'):'';
			serEndTime = workOrder.Install_End_Datetime__c != null ? workOrder.Install_End_Datetime__c.format('yyyy年MM月dd日'):'';
				if(workOrder.Install_End_Datetime__c != null )useSignDate = serEndTime;
			
			
				if(workOrder.Install_End_Datetime__c != null )engineerSignDate = serEndTime;

			
			engineerName = workOrder.Case__r.RecordType.DeveloperName == 'InstallationOrder' ? workOrder.Case__r.ServiceEngineerName__c : workOrder.Technician__r.Name;
			instruction= 			Utils.wrapWordInPdf(workOrder.Instruction__c, 			'\n', 36);
			installationDebugging= 	Utils.wrapWordInPdf(workOrder.InstallationDebugging__c, '\n', 70);
		}
    }
   
}